<?php
/**
 * Created by PhpStorm.
 * User: 清行
 * Date: 2019/3/18
 * Time: 22:02
 */
namespace xiaokang;

class Route{

    public $ctrl;
    public $action;
    public function __construct()
    {
        if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/xiaokang/' )
        {
           // dump($_SERVER);
            $path = $_SERVER['REQUEST_URI'];
            $patharr = explode('/',trim($path,'/'));

            if (isset($patharr[2]))
            {
                $this->ctrl = $patharr[2];
            }else{
                $this->ctrl = \xiaokang\Config::get('default_controller','config');
            }
            if (isset($patharr[3]))
            {
                $this->action = $patharr[3];
            }else{
                $this->action = \xiaokang\Config::get('default_action','config');
            }
            $count = count($patharr);
            $i=4;
            while ($i < $count)
            {
                if (isset($patharr[$i+1]))
                {
                    $_GET[$patharr[$i]] = $patharr[$i+1];
                }
                $i+=2;
            }
        }else{
            $this->ctrl = \xiaokang\Config::get('default_controller','config');
            $this->action = \xiaokang\Config::get('default_action','config');
        }
    }
}